<?php
namespace Content\Controller;
use Think\Controller;

/**
 * Class AdminNavController
 * @package Content\Controller
 * 后台栏目管理
 */
class AdminNavController extends Controller {
    private $model_name = 'Nav';

    public function index(){
        $this->display();
    }

    public function getAll(){
        $list = D($this->model_name);
        $list = $list->get_all();
        echo json_encode($list);
    }

    public function add(){
        $model = D($this->model_name);
        if(IS_POST){
            $data = filterInput($_POST);
            $model->addObj($data, 'id');
            $this->success(LANG('save_success'));
            return;
        }else if(IS_GET){
            $parent = $model->get_all_nav();
            $this->assign('parents', $parent);
        }
        $this->display();
    }

    public function edit(){
        $model = D($this->model_name);
        if(IS_POST){
            $post_data = filterInput($_POST);
            $model->save($post_data);
            $this->success(LANG('save_success'));
            return;
        }else if(IS_GET){
            $data = filterInput($_GET);
            $item = $model->queryObj($data['id'], 'id');
            $parent = $model->get_all_nav();
            $this->assign('parents', $parent);
            $this->assign('item', $item);
        }
        $this->display();
    }

    public function deleteArray(){
        $data = filterInput($_POST);
        echo $ids = $data['ids'];
        $model = D($this->model_name);
        $model->del($ids);
    }
}